from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-08 14:02:34.267070
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 08, Apr, 2022
Time: 14:02:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.8780
Nobs: 620.000 HQIC: -49.2710
Log likelihood: 7523.83 FPE: 3.11401e-22
AIC: -49.5210 Det(Omega_mle): 2.69637e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.335961 0.064232 5.230 0.000
L1.Burgenland 0.105932 0.040022 2.647 0.008
L1.Kärnten -0.110575 0.020945 -5.279 0.000
L1.Niederösterreich 0.196206 0.083661 2.345 0.019
L1.Oberösterreich 0.118292 0.082402 1.436 0.151
L1.Salzburg 0.259575 0.042456 6.114 0.000
L1.Steiermark 0.042103 0.055919 0.753 0.451
L1.Tirol 0.104552 0.045199 2.313 0.021
L1.Vorarlberg -0.065876 0.039933 -1.650 0.099
L1.Wien 0.020391 0.073398 0.278 0.781
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048820 0.137678 0.355 0.723
L1.Burgenland -0.038076 0.085785 -0.444 0.657
L1.Kärnten 0.042092 0.044894 0.938 0.348
L1.Niederösterreich -0.201430 0.179322 -1.123 0.261
L1.Oberösterreich 0.455281 0.176622 2.578 0.010
L1.Salzburg 0.282621 0.091001 3.106 0.002
L1.Steiermark 0.113683 0.119858 0.948 0.343
L1.Tirol 0.306044 0.096880 3.159 0.002
L1.Vorarlberg 0.027123 0.085593 0.317 0.751
L1.Wien -0.027561 0.157323 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191102 0.032838 5.820 0.000
L1.Burgenland 0.088750 0.020461 4.338 0.000
L1.Kärnten -0.007203 0.010708 -0.673 0.501
L1.Niederösterreich 0.244207 0.042771 5.710 0.000
L1.Oberösterreich 0.160254 0.042127 3.804 0.000
L1.Salzburg 0.040169 0.021705 1.851 0.064
L1.Steiermark 0.029049 0.028588 1.016 0.310
L1.Tirol 0.082923 0.023107 3.589 0.000
L1.Vorarlberg 0.054773 0.020415 2.683 0.007
L1.Wien 0.117682 0.037524 3.136 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112138 0.032868 3.412 0.001
L1.Burgenland 0.042408 0.020480 2.071 0.038
L1.Kärnten -0.013111 0.010718 -1.223 0.221
L1.Niederösterreich 0.174100 0.042810 4.067 0.000
L1.Oberösterreich 0.333739 0.042166 7.915 0.000
L1.Salzburg 0.100252 0.021725 4.615 0.000
L1.Steiermark 0.114001 0.028614 3.984 0.000
L1.Tirol 0.091167 0.023129 3.942 0.000
L1.Vorarlberg 0.060976 0.020434 2.984 0.003
L1.Wien -0.016226 0.037558 -0.432 0.666
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115382 0.061530 1.875 0.061
L1.Burgenland -0.045724 0.038338 -1.193 0.233
L1.Kärnten -0.045392 0.020064 -2.262 0.024
L1.Niederösterreich 0.138969 0.080142 1.734 0.083
L1.Oberösterreich 0.161482 0.078935 2.046 0.041
L1.Salzburg 0.284690 0.040670 7.000 0.000
L1.Steiermark 0.061559 0.053566 1.149 0.250
L1.Tirol 0.159403 0.043297 3.682 0.000
L1.Vorarlberg 0.098666 0.038253 2.579 0.010
L1.Wien 0.073427 0.070310 1.044 0.296
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057443 0.048159 1.193 0.233
L1.Burgenland 0.025576 0.030007 0.852 0.394
L1.Kärnten 0.053127 0.015704 3.383 0.001
L1.Niederösterreich 0.194443 0.062726 3.100 0.002
L1.Oberösterreich 0.331894 0.061782 5.372 0.000
L1.Salzburg 0.035939 0.031832 1.129 0.259
L1.Steiermark 0.013642 0.041926 0.325 0.745
L1.Tirol 0.120776 0.033888 3.564 0.000
L1.Vorarlberg 0.067545 0.029940 2.256 0.024
L1.Wien 0.100604 0.055031 1.828 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170000 0.057935 2.934 0.003
L1.Burgenland 0.005364 0.036099 0.149 0.882
L1.Kärnten -0.065728 0.018892 -3.479 0.001
L1.Niederösterreich -0.104387 0.075459 -1.383 0.167
L1.Oberösterreich 0.206678 0.074323 2.781 0.005
L1.Salzburg 0.054264 0.038293 1.417 0.156
L1.Steiermark 0.247973 0.050436 4.917 0.000
L1.Tirol 0.501696 0.040768 12.306 0.000
L1.Vorarlberg 0.064155 0.036018 1.781 0.075
L1.Wien -0.077456 0.066202 -1.170 0.242
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153695 0.064251 2.392 0.017
L1.Burgenland -0.002398 0.040034 -0.060 0.952
L1.Kärnten 0.062572 0.020951 2.987 0.003
L1.Niederösterreich 0.169861 0.083685 2.030 0.042
L1.Oberösterreich -0.055611 0.082425 -0.675 0.500
L1.Salzburg 0.207806 0.042468 4.893 0.000
L1.Steiermark 0.139892 0.055934 2.501 0.012
L1.Tirol 0.058075 0.045211 1.285 0.199
L1.Vorarlberg 0.147143 0.039944 3.684 0.000
L1.Wien 0.121631 0.073419 1.657 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.380621 0.037854 10.055 0.000
L1.Burgenland -0.003711 0.023586 -0.157 0.875
L1.Kärnten -0.020869 0.012344 -1.691 0.091
L1.Niederösterreich 0.203986 0.049305 4.137 0.000
L1.Oberösterreich 0.230836 0.048562 4.753 0.000
L1.Salzburg 0.036962 0.025021 1.477 0.140
L1.Steiermark -0.012452 0.032955 -0.378 0.706
L1.Tirol 0.089708 0.026637 3.368 0.001
L1.Vorarlberg 0.052280 0.023534 2.222 0.026
L1.Wien 0.045200 0.043256 1.045 0.296
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036999 0.110315 0.173573 0.139718 0.102927 0.081825 0.036129 0.211616
Kärnten 0.036999 1.000000 -0.025730 0.130912 0.049379 0.085453 0.443525 -0.066198 0.089975
Niederösterreich 0.110315 -0.025730 1.000000 0.315395 0.122658 0.276495 0.068728 0.155082 0.294575
Oberösterreich 0.173573 0.130912 0.315395 1.000000 0.214271 0.297972 0.166491 0.138620 0.241106
Salzburg 0.139718 0.049379 0.122658 0.214271 1.000000 0.126020 0.093382 0.106086 0.126952
Steiermark 0.102927 0.085453 0.276495 0.297972 0.126020 1.000000 0.135466 0.110622 0.039670
Tirol 0.081825 0.443525 0.068728 0.166491 0.093382 0.135466 1.000000 0.065436 0.151229
Vorarlberg 0.036129 -0.066198 0.155082 0.138620 0.106086 0.110622 0.065436 1.000000 -0.003131
Wien 0.211616 0.089975 0.294575 0.241106 0.126952 0.039670 0.151229 -0.003131 1.000000